import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";

Vue.use(Vuex);

const store = new Vuex.Store({
  plugins: [createPersistedState()],
  state: {
    token: "",
    username: "",
    password: "",
    qq: "",
    code: "", // 响应状态码
    msg: "", // 状态描述
  },
  mutations: {
    Login(state, data) {
      state.token = data.token;
      state.username = data.phone;
      state.password = data.pwd;
      state.qq = +data.qq;
      state.code = "0";
    },
    Logout(state) {
      state.token = "";
      state.username = "";
      state.password = "";
      state.qq = "";
      state.expiresCode = "";
      state.code = "";
      state.msg = "";
    },
    editPwd(state, data) {
      state.password = data.newPwd;
    },
    editQQ(state, data) {
      state.qq = data.newQQ;
    },
    changeCode(state, data) {
      state.code = data.code;
      state.msg = data.msg;
    },
  },
  actions: {},
  modules: {},
  getters: {},
});

export default store;
